<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" />
  <meta name="misapplication-tap-highlight" content="no" />
  <meta name="HandheldFriendly" content="true" />
  <meta name="MobileOptimized" content="320" />
  <link rel="stylesheet" href="cs.css">
  <title>QmSdk-Other</title>
</head>

<body>
  <div class="title">拨打电话</div>
  <div class="user" onclick="call(this)">
    <div class="user-name">张三</div>
    <div class="user-number">18011111111</div>
  </div>
  <div class="user" onclick="call(this)">
    <div class="user-name">李四</div>
    <div class="user-number">18022222222</div>
  </div>

  <div class="title">文件上传</div>
  <div class="button" onclick="fileUpload()">
    文件上传
  </div>

  <div class="title">语音识别</div>
  <div class="button" onclick="startRecord()">
    开始识别
  </div>
  <div class="info record">
  </div>


  <div class="title">扫描二维码</div>
  <div class="button" onclick="scanCodeCard()">
    扫描二维码
  </div>

  <div class="title">获取网络状态</div>
  <div class="button" onclick="getNetworkConnectType()">
    获取网络状态
  </div>
  <div class="info network">
  </div>

  <div class="title">录音</div>
  <div class="button" onclick="startRecorder()">
    开始录音
  </div>
  <div class="button" onclick="stopRecorder()">
    结束录音
  </div>
  <div class="info recorder">
  </div>
  <ul class="recorder-list">
  </ul>
  <div style="margin: 1em 0;display: flex;gap: .5em;">
    <div class="button" onclick="audioPlayerPause()">暂停</div>
    <div class="button" onclick="audioPlayerResume()">继续</div>
    <div class="button" onclick="audioPlayerStop()">停止</div>
  </div>

  <div class="title">拍照</div>
  <div class="button" onclick="camera()">
    拍照
  </div>

  <div class="title">下载</div>
  <div class="inputItem">URL：<input type="text"
      placeholder="https://fanyi-cdn.cdn.bcebos.com/static/translation/img/header/logo_e835568.png" class="input url" />
  </div>
  <div class="button" onclick="downloader()">
    下载
  </div>
  <div class="info downloader"></div>

  <div class="title">指纹识别</div>
  <div class="button" onclick="fingerprint()">
    指纹识别
  </div>

  <div class="title">发短信、邮件</div>
  <div class="inputItem"><span class="label">类型：</span>
    <select class="select" name="msgType" id="msgType">
      <!-- <option value="">--请选择--</option> -->
      <option value="SMS">短信</option>
      <option value="MMS">彩信</option>
      <option value="EMAIL">邮件</option>
    </select>
  </div>
  <div class="inputItem"><span class="label">接收人：</span><input type="text" value="123456abc@qq.com"
      class="input msgTo" /></div>
  <div class="inputItem"><span class="label">抄送：</span><input type="text" value="123456aa@123.com"
      class="input msgCc" /></div>
  <div class="inputItem"><span class="label">暗送：</span><input type="text" value="112233@163.com" class="input msgBcc" />
  </div>
  <div class="inputItem"><span class="label">发件人信息：</span><input type="text" value="测试测试测试" class="input msgFrom" />
  </div>
  <div class="inputItem"><span class="label">主题：</span><input type="text" value="测试" class="input msgSubject" />
  </div>
  <div class="inputItem"><span class="label">消息内容：</span><input type="text" value="测试测试测试测试" class="input msgBody" />
  </div>
  <div class="inputItem"><span class="label"><del>附件：</del></span><input type="file" placeholder="暂时无效"
      class="input msgFile" disabled /></div>
  <div class="inputItem">
    <span class="label">内容类型：</span>
    <select class="select" name="msgBodyType" id="msgBodyType">
      <option value="text">文本</option>
      <option value="html">html页面</option>
    </select>
  </div>
  <div class="button" onclick="send()">
    发送
  </div>

  <div class="title">分享</div>
  <div class="button" onclick="share()">分享</div>
  <div class="info share"></div>

  <script src="../qmsdk.js"></script>
  <script>
    let recordInfoBox = document.querySelector(".info.record");
    let networkInfoBox = document.querySelector(".info.network");
    let recorderInfoBox = document.querySelector(".info.recorder");
    let downloaderInfoBox = document.querySelector(".info.downloader");
    let shareInfoBox = document.querySelector(".info.share");
    // 保存播放器对象
    let player;

    // 打电话
    function call(e) {
      let phone = e.children[1].innerText;
      qmSdk.call({
        phone,
        success: res => {
          console.log(phone + " :拨打成功");
        }
      })
    }

    // 文件上传
    function fileUpload() {
      console.log("fileUpload");
      qmSdk.fileUpload({
        uploaditem: [2],
        uploadurl: "http://192.168.2.22:8085/upload",
        params: {
          xxxid: "abcdefg",
          xxxid1: "hijklmn",
        },
        itemproperty: {
          maximagescount: 3,
        },
        success: (r) => {
          console.log(r);
          console.log(JSON.parse(r.responseText));
          alert("上传成功")
        }
      })
    }


    // 语音识别
    function startRecord() {
      let p = document.createElement("p");
      recordInfoBox.appendChild(p);
      qmSdk.startRecord({
        success: res => {
          console.log("识别结果：-->", JSON.stringify(res));
          p.innerText = res;
        },
        fail: err => {
          console.log(JSON.stringify(err));
          if (err.code === 3101) {
            p.innerText = "你好像还没讲话呢";
            return;
          }
          p.innerText = "识别失败";
        }
      })
    }

    // 扫描二维码 - 暂无
    function scanCodeCard() {
      qmSdk.scanCodeCard({})
    }

    // 获取网络状态
    function getNetworkConnectType() {
      qmSdk.getNetworkConnectType({
        success: res => {
          let p = document.createElement("p");
          p.innerText = "您的网络类型为：" + res.connectType;
          networkInfoBox.appendChild(p);
        }
      })
    }

    function startRecorder() {
      let p = document.createElement("p");
      recorderInfoBox.appendChild(p);
      qmSdk.startRecorder({
        success: res => {
          console.log(JSON.stringify(res));
          p.innerText = "录音文件保存位置：" + res;
          let list = document.querySelector(".recorder-list");
          let item = document.createElement("li");
          item.setAttribute("onclick", "audioPlayer('" + res + "')")
          item.innerHTML = "<div>" + res + "</div>"
          list.appendChild(item);
        },
        fail: err => {
          console.log(JSON.stringify(err));
        }
      })
    }

    function stopRecorder() {
      qmSdk.stopRecorder({
        success: res => {
          console.log(JSON.stringify(res));
        }
      })
    }

    function audioPlayer(path) {
      console.log(path);
      qmSdk.audioPlayer({
        audio: path,
        success: res => {
          player = res;
          player.play();
        }
      })
    }

    function audioPlayerPause() {
      if (player) {
        player.pause();
      }
    }

    function audioPlayerResume() {
      if (player) {
        player.resume();
      }
    }

    function audioPlayerStop() {
      if (player) {
        player.stop();
      }
    }

    function camera() {
      qmSdk.camera({
        index: 0,
        success: res => {
          res.captureImage(r => {
            console.log(r);
          }, e => {
            console.log(JSON.stringify(e));
          }, {
            filename: "_doc/camera/",
          });
        }
      })
    }

    function downloader() {
      qmSdk.downloader({
        url: document.querySelector(".input.url").value ||
          "https://fanyi-cdn.cdn.bcebos.com/static/translation/img/header/logo_e835568.png",
        options: {
          method: "GET",
          filename: "_doc/download/"
        },
        success: res => {
          console.log(JSON.stringify(res));
          let p = document.createElement("p");
          p.innerText = `文件下载完毕: ${res.filename} size: ${res.downloadedSize}`
          downloaderInfoBox.appendChild(p);
        }
      })
    }

    function fingerprint() {
      if (!window.plus) {

      }
      qmSdk.fingerprint({
        success: res => {
          console.log(JSON.stringify(res), "指纹识别成功");
        },
        fail: err => {
          console.log(JSON.stringify(err), "指纹识别失败");
        }
      })
    }

    function send() {

      let type = document.querySelector("#msgType").value;
      let to = document.querySelector(".msgTo").value.split(",");
      let body = document.querySelector(".msgBody").value;
      let cc = document.querySelector(".msgCc").value.split(",");
      let bcc = document.querySelector(".msgBcc").value.split(",");
      let from = document.querySelector(".msgFrom").value;
      let subject = document.querySelector(".msgSubject").value;
      let bodyType = document.querySelector("#msgBodyType").value;

      qmSdk.messaging({
        type,
        to,
        body,
        cc,
        bcc,
        from,
        subject,
        bodyType,
        // files: [files.filename],
        success: res => {
          console.log(JSON.stringify(res), 1);
        },
        fail: err => {
          console.log(JSON.stringify(err), 0);
        }
      })
    }

    function share() {
      qmSdk.share({
        success: res => {
          console.log(JSON.stringify(res));
          let p = document.createElement("p");
          shareInfoBox.appendChild(p);
          p.appendChild(document.createTextNode("可分享列表: "));
          // p.innerText = "asasas"
          res.map(v => {
            p.appendChild(document.createTextNode("[" + v.id + "|" + v.description + "]"));
          })

          res.map(v => {
            if (v.id === "weixin") {
              let msg = {
                type: "web", // 类型
                title: "齐明软件八周年 | 八年同心，相伴未来！", // 标题
                content: "八年同心，砥砺奋进，齐明人初心不变。八年相伴，乘风而上，齐明人创新未来。齐明软件八周年，八年同心，相伴未来！", // 类容
                thumbs: [
                  "http://www.championsoft.cn/image/common/logo-tp.svg"
                ], // 缩略图
                href: "http://www.championsoft.cn/news/c5aa2012-e80b-4135-8f2d-e02167c5b815", // 链接
                extra: {
                  scene: "WXSceneSession" // 'WXSceneSession'分享给好友，'WXSceneTimeline'分享到朋友圈
                },
              }
              v.send(msg, () => {
                console.log("分享成功");
              }, err => {
                console.log('分享失败', JSON.stringify(err));
              });
            }
          })

        },
        fail: err => {
          console.log("err", JSON.stringify(err));
        }
      })
    }

  </script>
</body>

</html>
